
import 'package:flutter_map_demo/t3_map_plugin/map/core/t3_base_overlay.dart';

import 't3_location.dart';

class T3Polyline extends T3BaseOverlay {
  T3PolylineOptions options;

  T3Polyline(this.options);

  void update({required List<T3LocationCoordinate2D> points}) {
    options.points = points;
  }

  Map<String, dynamic> toJson() {
    var json = options.toJson();
    json["uid"] = id;
    return json;
  }
}

class T3PolylineOptions {
  List<T3LocationCoordinate2D> points;
  final String? routeID;
  final T3PolylineStyle style;
  T3PolylineLabel? label;

  T3PolylineOptions(
      {required this.points, this.routeID, required this.style, this.label});

  Map<String, dynamic> toJson() {
    return {
      "style": style.toJson(),
      "routeID": routeID,
      "points": points.map((e) => e.toList()).toList(),
      "label": label?.toJson()
    };
  }
}

class T3PolylineStyle {
  final T3PolylineType lineType = T3PolylineType.normal;
  final double width;
  final T3PolylineDashStyle lineDashType;
  final T3PolylineJoinStyle lineJoinType;
  final T3PolylineCapStyle lineCapType;
  final double miterLimit;
  final String? fillColorValue;
  final String? strokeColorValue;

  const T3PolylineStyle({
    required this.width,
    this.lineDashType = T3PolylineDashStyle.none,
    this.lineCapType = T3PolylineCapStyle.butt,
    this.lineJoinType = T3PolylineJoinStyle.bevel,
    this.miterLimit = 2.0,
    required this.fillColorValue,
    required this.strokeColorValue,
  });

  Map<String, dynamic> toJson() {
    return {
      'width': width,
      'miterLimit': miterLimit,
      'lineDashType': lineDashType.value,
      'lineCapType': lineCapType.value,
      'lineJoinType': lineJoinType.value,
      'fillColorValue': fillColorValue,
      'strokeColorValue': strokeColorValue,
      'lineType': lineType.value,
    };
  }
}

class T3MultiPolylineStyle extends T3PolylineStyle {
  @override
  final T3PolylineType lineType = T3PolylineType.multi;

  /// 路况描述
  final String? traffic;

  /// 选中状态
  bool isSelected;

  T3MultiPolylineStyle({
    required super.width,
    super.lineDashType = T3PolylineDashStyle.none,
    super.lineCapType = T3PolylineCapStyle.butt,
    super.lineJoinType = T3PolylineJoinStyle.bevel,
    super.miterLimit = 2.0,
    super.fillColorValue,
    super.strokeColorValue,
    this.isSelected = false,
    this.traffic,
  });

  @override
  Map<String, dynamic> toJson() {
    return {
      'width': width,
      'miterLimit': miterLimit,
      'lineDashType': lineDashType.value,
      'lineCapType': lineCapType.value,
      'lineJoinType': lineJoinType.value,
      'fillColorValue': fillColorValue,
      'strokeColorValue': strokeColorValue,
      'traffic': traffic,
      'isSelected': isSelected,
      'lineType': lineType.value,
    };
  }
}

class T3PolylineLabel {
  String? title;
  String? subTitle;
  String? time; // 分钟
  String? distance; // 公里

  T3PolylineLabel({this.title, this.subTitle, this.time, this.distance});

  @override
  Map<String, dynamic> toJson() {
    return {
      'title': title,
      'subTitle': subTitle,
      'time': time,
      'distance': distance,
    };
  }
}

enum T3PolylineType {
  normal(0),

  /// 标准线
  multi(1);

  /// 多彩线路(路况等)

  final int value;

  const T3PolylineType(this.value);
}

enum T3PolylineDashStyle {
  none(0),

  /// 实线
  square(1),

  /// 方块样式
  dot(2);

  /// 圆点样式

  final int value;

  const T3PolylineDashStyle(this.value);
}

enum T3PolylineJoinStyle {
  bevel(0),

  /// 实线
  miter(1),

  /// 方块样式
  round(2);

  /// 圆点样式

  final int value;

  const T3PolylineJoinStyle(this.value);
}

enum T3PolylineCapStyle {
  butt(0),

  ///< 普通头
  square(1),

  ///< 扩展头
  arrow(2),

  ///< 箭头
  round(3);

  ///< 圆形头

  final int value;

  const T3PolylineCapStyle(this.value);
}
